#ifndef _NOTE_H
#define _NOTE_H

#include <wx/string.h>
#include "debug.h"
#include "keyword.h"

class Note : private InstanceWatcher<Note>
{
private:

public:
    /// Unique ID for each note. This is assigned by DB engine upon write to database.
    /// Value 0 is used for new notes prior to writing them into database.
    int id;

    /// Descriptive caption of note (can be empty)
    wxString caption;

    /// Date in original format as entered by user.
    /// (can be empty, but if nonempty must be valid according to ParseDate())
    wxString date;

    /// List of manual keywords entered by user.
    /// Besides these, keywords can also be enclosed in brackets inside note text.
    /// Those are collected on each setText() and stored along with manual keywords
    /// in member variable 'keywords'.
    wxString manual_keywords;

    /// Text of note.
    wxString text;

    /// time of creation
    long created;

    /// time of last modification
    long modified;

    Note() {
        this->id=0;
        this->date = L"";
        this->manual_keywords = L"";
        this->text = L"";
        created = 0;
        modified = 0;
    }

    /// Check if note is empty (all values same as default by constructor)
    inline bool isEmpty() const {
        return id==0 && date==L"" && manual_keywords==L"" && text==L"" && created==0 && modified==0;
    }

    /// Simple conversion of note to multi-line text. Mainly for message boxes.
    /// TODO: update to include new members
    wxString FormatForDisplay() const;

    /// Quick & dirty convert Note to single-line string, mainly for debug log.
    /// TODO: update to include new members
    wxString ToString() const;

    /// Get list of all keywords, from both text and manual keywords. Useful for database.
    wxString ParseAllKeywords() const;

    bool MatchesBody(const wxString) const;
    static int CompareDates(const wxString& date1, const wxString& date2);
    int CompareDateTo(const wxString& date2) const;
    int CompareDateTo(const Note& note2) const;
    bool ExtractDate(int *year, int *month, int *day) const;
};

extern int Note_instance_count;

/// Checks whether string contains correctly formated date.
/// @return true if date format is valid
bool CheckDate(const wxString& fromwx);

/// @return true if date format is valid
bool ParseDate(const wxString& fromwx, wxString& sortdate);

wxString ParseDate(const wxString& s);
bool ExtractDate(const wxString& date, int *year, int *month, int *day);
bool GetEndDate(const wxString& date, wxString* enddate);

#endif
